package com.bangyu.monitor.modular.system.service;

import com.bangyu.monitor.core.common.page.LayuiPageFactory;
import com.bangyu.monitor.modular.system.entity.MaintainRecord;
import com.bangyu.monitor.modular.system.mapper.MaintainRecordMapper;
import com.bangyu.monitor.modular.system.model.MaintainRecordDto;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Auther: zhangxue
 * @Date: 19/4/8 16:10
 * @Description:
 */
@Service
public class MaintainRecordService extends ServiceImpl<MaintainRecordMapper,MaintainRecord> {

    List<MaintainRecord> getByBridgeId(Long bridgeId){
        return baseMapper.getByBridgeId(bridgeId);
    }


    public void addRecord(MaintainRecordDto dto) {
        MaintainRecord record = MaintainRecord.dtoToModule(dto);
        this.save(record);
    }

    /**
     * 分页查询桥梁维修记录
     * @param bridgeName
     * @return
     */
    public Page<Map<String,Object>> pageAll(String bridgeName){
        Page page = LayuiPageFactory.defaultPage();
        return this.baseMapper.pageAll(page,bridgeName);
    }


    public void update(MaintainRecordDto dto){
        MaintainRecord record = MaintainRecord.dtoToModule(dto);
        this.updateById(record);
    }

    /**
     * 一段时间内维修桥的数量
     * @param bridgeIds
     * @param startDate
     * @param endDate
     * @return
     */
    public Integer bridgeCountOfMaintain(List<Long> bridgeIds,Integer startDate,Integer endDate){
        return this.baseMapper.bridgeCountOfMaintain(bridgeIds,startDate,endDate);
    }
}
